package exam.model.dao;

import java.util.List;

import exam.common.util.NullCheckUtil;
import exam.model.entity.TUserEntity;

public class UserDao extends AbstractDao<TUserEntity>{
	
	public UserDao() {
		super(TUserEntity.class);
	}
	
	public List<TUserEntity> selectListUser() {
		return super.selectList("from TUserEntity");
	}
	
	public TUserEntity selectByPk(long id) {
		return super.selectByPk(id);
	}
	
	public TUserEntity selectByUserName(String username) {
		String query = "select u from TUserEntity u where u.userName='" + username + "'";
		return super.jdbcManager.executeByQuery(query).getSingleResult();
	}
	
	public boolean insertUser(TUserEntity user) {
		if (NullCheckUtil.isNotNull(selectByUserName(user.getUserName()))) {
			return false;
		}
		super.insert(user);
		return true;
	}
	
	public void updateUser(TUserEntity user) {
			super.update(user);
	}
	
	public boolean deleteUser(long id) {
		if (NullCheckUtil.isNUll(selectByPk(id))) {
			return false;
		}
		super.delete(id);
		return true;
		
	}
}
